package com.bnzj.cloud.business.core.persistence.entity;

import com.bnzj.core.persistence.entity.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author barry
 * @date 2019-09-27
 */
@Getter
@Setter
//callSuper = true，在输出中包括超类的toString实现的结果
//exclude = "child"，在输出中排除掉child字段，否则toString会死循环
@ToString(exclude = "child", callSuper = true)
@Entity
@Table(name = "bnz_sys_dictionary_type")
@Schema(description = "数据字典类型")
public class SysDictionaryType extends BaseEntity {
    private static final long serialVersionUID = -3095253048913207590L;
    @Schema(description = "名称")
    @NotNull(message = "名称不能为空！")
    private String name;
    @Schema(description = "编码")
    @NotNull(message = "编码不能为空！")
    private String code;
    @Schema(description = "描述")
    private String description;

    @OneToMany(targetEntity = SysDictionary.class, cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY)
    @JoinColumn(name = "typeId", updatable = false, insertable = false)
    @Where(clause = "deleted = 0")
    private List<SysDictionary> child;
}
